package cn.ffcs.uec.common.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.ffcs.uec.common.component.UecBdDefdocTreeBandboxExt;
import cn.ffcs.uec.organization.vo.OrganizationRelationVo;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.zkplus.zul.tree.node.TreeNodeEntity;
import lombok.Getter;
import lombok.Setter;

/**
 * 自定义档案虚拟类--字典类
 * 
 * @Title:
 * @Description:
 * @author Wang Yiren
 * @版权 FFCS（C） 2017
 * @date 2018年6月25日
 */
public class UecBdDefdoc implements Serializable, TreeNodeEntity {

    private static final long serialVersionUID = 2822398252170974011L;

    public UecBdDefdocTreeBandboxExt component; // 所在组件

    private boolean end;// 是否末端节点

    @Getter
    @Setter
    private Long staffId;

    @Getter
    @Setter
    private Long monthId;

    @Getter
    @Setter
    private String unitId;

    @Getter
    @Setter
    private String code;

    @Getter
    @Setter
    private String creationTime;

    @Getter
    @Setter
    private String creator;

    @Getter
    @Setter
    private Long dataoriginFlag;

    @Getter
    @Setter
    private Long dataType;

    @Getter
    @Setter
    private Long dr;

    @Getter
    @Setter
    private String enableState;

    @Getter
    @Setter
    private String innerCode;

    @Getter
    @Setter
    private String memo;

    @Getter
    @Setter
    private String mneCode;

    @Getter
    @Setter
    private String modifiedTime;

    @Getter
    @Setter
    private String modifier;

    /**
     * 关联主键得名字
     */
    @Getter
    @Setter
    private String name;

    @Getter
    @Setter
    private String name2;

    @Getter
    @Setter
    private String name3;

    @Getter
    @Setter
    private String name4;

    @Getter
    @Setter
    private String name5;

    @Getter
    @Setter
    private String name6;

    @Getter
    @Setter
    private String pid;

    @Getter
    @Setter
    private String pkDefdoc;

    @Getter
    @Setter
    private String pkDefdoclist;

    @Getter
    @Setter
    private String pkGroup;

    @Getter
    @Setter
    private String pkOrg;

    @Getter
    @Setter
    private String shortName;

    @Getter
    @Setter
    private String shortName2;

    @Getter
    @Setter
    private String shortName3;

    @Getter
    @Setter
    private String shortName4;

    @Getter
    @Setter
    private String shortName5;

    @Getter
    @Setter
    private String shortName6;

    @Getter
    @Setter
    private String ts;

    public UecBdDefdocTreeBandboxExt getComponent() {
        return component;
    }

    public void setComponent(UecBdDefdocTreeBandboxExt component) {
        this.component = component;
    }

    public boolean isEnd() {
        return end;
    }

    public void setEnd(boolean end) {
        this.end = end;
    }

    public static UecBdDefdoc newInstance() {
        return new UecBdDefdoc();
    }

    /**
     * 根据指定flag
     * 展示指定根节点标识
     * 
     */
    // TODO 注意：表UecBdDefdoc 是一张综合类型集团下发的树形字典表，由于每个类型的树的 PID  父节点都是"~"，所以在省内处理的时候
    // 将每个阶段的树形字典 的pid进行了自定义，以方便数据处理，其次为了复用UecBdDefdocTreeBandboxExt、UecBdDefdocTree类
    // 在下次调用不同的树形结构是只需这样操作：<uecBdDefdocTreeBandboxExt id="newPostLevel"
    // width="93%" mode="multipleSelection" flag="newPostLevel" />    flag="newPostLevel",就是数据
    // UecBdDefdoc表中的自定义的父节点
    @Getter
    @Setter
    private String flag;

    /**
     * 是否是根节点
     */
    @Getter
    @Setter
    private Boolean isRoot = false; // 设置为true则表示用来获取根节点

    public boolean isGetRoot() {
        return this.isRoot;
    }

    @SuppressWarnings("unchecked")
    @Override
    public ArrayList<TreeNodeEntity> getRoot() {
        String sqlStr = " SELECT *  FROM UEC_BD_DEFDOC WHERE PID = ? ";
        List<Object> params = new ArrayList<Object>();
        if (this.flag == null) {
            flag = "";
        }
        params.add(this.flag);
        List<UecBdDefdoc> list = OrganizationRelationVo.repository().jdbcFindList(sqlStr, params,
                UecBdDefdoc.class);
        Object object = list;
        return (ArrayList<TreeNodeEntity>) object;
    }

    @SuppressWarnings("unchecked")
    @Override
    public ArrayList<TreeNodeEntity> getChildren() {
        if (!StrUtil.isNullOrEmpty(this.pkDefdoc)) {
            String sqlStr = " SELECT * FROM UEC_BD_DEFDOC WHERE PID = ? ORDER BY mnecode ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.pkDefdoc);
            List<UecBdDefdoc> list = OrganizationRelationVo.repository().jdbcFindList(sqlStr,
                    params, UecBdDefdoc.class);
            Object object = list;
            return (ArrayList<TreeNodeEntity>) object;
        }
        return null;
    }

    @Override
    public String getLabel() {
        if (!StrUtil.isNullOrEmpty(this.name)) {
            return this.name;
        } else {
            return "";
        }
    }
}
